<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        width: 100px;
        color: red;
      }
      #box::after {
        content: "hello";
        color: gray;
      }
    </style>
  </head>
  <body>
    <div id="box" style="width: 400px; font-size: 2rem; border: solid">
      hello div
    </div>
    <script>
      const box = document.getElementById("box");

      // 最终计算出来的样式
      const style = getComputedStyle(box);
      console.log(style.width); //内联样式
      console.log(style.height); //默认样式
      console.log(style.color); //标签样式

      const stylePs = getComputedStyle(box, "::after");
      console.log(stylePs.color);
      console.log(stylePs.width);
    </script>
  </body>
</html>
